package ebuy.com.cotroller;

import ebuy.com.config.Handleexception;
import ebuy.com.pojo.Commodity;
import ebuy.com.server.Commodityserver;
import ebuy.com.util.RespBean;
import ebuy.com.vo.Commodityvo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CommodityCotroller {
    private Logger logger = LoggerFactory.getLogger(CommodityCotroller.class);





    @Autowired
    private Commodityserver commodityserver;
    @GetMapping("/getsha")
    public RespBean GetSHanmg(@RequestParam("id")Integer id){
        List<Commodity> checkpopularproducts =commodityserver.Checkpopularproducts(id);
        return RespBean.success("热门商品",checkpopularproducts);
    }
    @GetMapping("/getuu")
    public RespBean GetCommodity(@RequestParam("id") Integer id){
        Commodity queryaccordingtotheidoftheproduct = commodityserver.Queryaccordingtotheidoftheproduct(id);
        return RespBean.success("商品展示",queryaccordingtotheidoftheproduct);

    }
    @GetMapping("/getid")
    public RespBean GETUsaname(@RequestParam("usersname") String longname){
        List<Commodity> checkshoppingcart = commodityserver.Checkshoppingcart(longname);
        logger.info("购物车功能"+checkshoppingcart.toString());
        return RespBean.success("查询成功",checkshoppingcart);
    }
    @GetMapping("/lllll")
    public RespBean GETBBB(String longname){
        Integer checkthebalanceoftheshoppingcart = commodityserver.Checkthebalanceoftheshoppingcart(longname);
        return RespBean.success("查询成功",checkthebalanceoftheshoppingcart);

    }
    @GetMapping("/ooo")
    public RespBean Payforgoods(@RequestParam("longname") String longname){
        List<Commodityvo> paidmerchandisedisplay = commodityserver.Paidmerchandisedisplay(longname);
        return RespBean.success("查询成功",paidmerchandisedisplay);

    }
    @PostMapping(value = "/pp",produces = {"application/json;charset=UTF-8"})
     public RespBean Checkproductsaccordingtoshoppingcart( String s){
        System.out.println(s);

        String[] str = s.split(",");
        String t="";
        for (int i = 0; i <str.length ; i++) {
            System.out.println(str[i]);
            String s1 = commodityserver.Queryaccordingtoshoppingcartid(Integer.parseInt(str[i]));
            t=t+s1;
        }
        System.out.println(t);
       return RespBean.success("查询成功",t);
    }
}
